const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { WebpackManifestPlugin } = require('webpack-manifest-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const webpack = require('webpack');

module.exports = {
  mode: 'development', //production
  devtool: 'inline-source-map',
  entry: {
    app: {
      import: './src/index.js',
      dependOn: 'shared',
    },
    shared: 'lodash',
  },
  output: {
    filename: '[name].[chunkhash].bundle.js',
    path: path.resolve(__dirname, 'dist'),
    clean: true,
  },
  optimization: {
    runtimeChunk: 'single',
  },
  plugins: [
    new HtmlWebpackPlugin({
      title: 'Output Management',
      template: path.resolve(__dirname, 'public/index.html')
    }),
    new WebpackManifestPlugin(),
    new BundleAnalyzerPlugin(),
  ],
  devServer: {
    port: 3002,
  },
  module: {
    rules: [
      {
        test: /\.css$/i, // 正则表达式匹配
        use: ['style-loader','css-loader'],
        
      },
      {
        test: /\.(png|svg|jpg|jpeg|gif)$/i,
        type: 'asset/resource',
      },
      {
        test: /\.scss$/i, // sass loader
        use:[
          'style-loader',{
          loader: 'css-loader',
          options: {
            sourceMap: true
          }
          },{
            loader: 'sass-loader',
            options: {
              sourceMap: true
            }
          },{
            loader: 'postcss-loader'
          }
        ]
      }
    ]
  }
}